/*
 * SurfaceUI.java
 *
 * Created on 29 April 2008, 10:58
 */
package com.dabarobjects.mobile.ui;

import com.dabarobjects.mobile.ui.actions.ActionResultListener;
import com.dabarobjects.mobile.ui.actions.ApplicationServiceManager;
import com.dabarobjects.mobile.ui.actions.DiallingServiceManager;
import com.dabarobjects.mobile.ui.actions.PlaceCallAction;
import com.dabarobjects.mobile.ui.actions.ScanDevicesAction;
import com.dabarobjects.mobile.ui.models.BluetoothDevicesTableModel;
import com.dabarobjects.ui.surfaces.utils.WindowUtils;
import java.awt.Color;
import java.util.List;
import javax.bluetooth.RemoteDevice;

/**
 *
 * @author  user
 */
public class DialSurfaceUI extends javax.swing.JFrame implements ActionResultListener<List<RemoteDevice>> {

    private DiallingServiceManager manager;

    /** Creates new form SurfaceUI */
    public DialSurfaceUI() {
        initComponents();
        configureSurface();

        dvTableModel = new BluetoothDevicesTableModel();
    }

    private void configureSurface() {
        Color c = new Color(153, 204, 0);
        getContentPane().setBackground(c);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        contextMenu = new javax.swing.JPopupMenu();
        contextHeading = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        scanDevicesAction1 = new com.dabarobjects.mobile.ui.actions.ScanDevicesAction(this);
        bluetoothDevicesTableModel1 = new com.dabarobjects.mobile.ui.models.BluetoothDevicesTableModel();
        roundedBlackPanel1 = new com.dabarobjects.ui.surfaces.RoundedBlackPanel();
        foundDevicesTable = new com.dabarobjects.ui.surfaces.components.CustomTableView3(true);
        statusLabel = new com.dabarobjects.ui.surfaces.components.FadeLabel2();
        statusTable = new com.dabarobjects.ui.surfaces.components.CustomTableView3(true);
        fadeButton1 = new com.dabarobjects.ui.surfaces.components.FadeButton();
        startButton = new com.dabarobjects.ui.surfaces.components.FadeButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        contextHeading.setFont(new java.awt.Font("Trebuchet MS", 1, 12));
        contextHeading.setText("Item");
        contextMenu.add(contextHeading);
        contextMenu.add(jSeparator1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        statusLabel.setText("Status");
        statusLabel.setFont(new java.awt.Font("Trebuchet MS", 0, 14));

        fadeButton1.setAction(scanDevicesAction1);

        startButton.setText("Dial Number...");
        startButton.setToolTipText("Dial Number");
        startButton.setEnabled(false);
        startButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout roundedBlackPanel1Layout = new javax.swing.GroupLayout(roundedBlackPanel1);
        roundedBlackPanel1.setLayout(roundedBlackPanel1Layout);
        roundedBlackPanel1Layout.setHorizontalGroup(
            roundedBlackPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(roundedBlackPanel1Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(roundedBlackPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fadeButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
                    .addComponent(foundDevicesTable, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(roundedBlackPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(roundedBlackPanel1Layout.createSequentialGroup()
                        .addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(statusTable, javax.swing.GroupLayout.PREFERRED_SIZE, 433, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        roundedBlackPanel1Layout.setVerticalGroup(
            roundedBlackPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(roundedBlackPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(roundedBlackPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(roundedBlackPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                        .addComponent(startButton, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                    .addComponent(fadeButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(roundedBlackPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(statusTable, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
                    .addComponent(foundDevicesTable, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE))
                .addContainerGap())
        );

        jMenu1.setText("Options");
        jMenu1.setFont(new java.awt.Font("Trebuchet MS", 1, 12));

        jMenuItem1.setText("Exit");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(roundedBlackPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(roundedBlackPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
// TODO add your handling code here:
    System.exit(0);
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed
// TODO add your handling code here:
    if (manager != null) {
        
        
       
    }
}//GEN-LAST:event_startButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new DialSurfaceUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.dabarobjects.mobile.ui.models.BluetoothDevicesTableModel bluetoothDevicesTableModel1;
    private javax.swing.JMenuItem contextHeading;
    private javax.swing.JPopupMenu contextMenu;
    private com.dabarobjects.ui.surfaces.components.FadeButton fadeButton1;
    private com.dabarobjects.ui.surfaces.components.CustomTableView3 foundDevicesTable;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JSeparator jSeparator1;
    private com.dabarobjects.ui.surfaces.RoundedBlackPanel roundedBlackPanel1;
    private com.dabarobjects.mobile.ui.actions.ScanDevicesAction scanDevicesAction1;
    private com.dabarobjects.ui.surfaces.components.FadeButton startButton;
    private com.dabarobjects.ui.surfaces.components.FadeLabel2 statusLabel;
    private com.dabarobjects.ui.surfaces.components.CustomTableView3 statusTable;
    // End of variables declaration//GEN-END:variables
    private BluetoothDevicesTableModel dvTableModel;
    private PlaceCallAction placeCallAction;
    public void onActionComplete(List<RemoteDevice> t) {

        dvTableModel.setDevices(t);
        foundDevicesTable.getTable().setModel(dvTableModel);

        manager = new DiallingServiceManager(foundDevicesTable.getTable(), contextMenu, contextHeading);
        manager.configure();
        manager.setChannelStatusLabel(statusLabel);
        
        startButton.setEnabled(true);
        placeCallAction = new PlaceCallAction(manager);
         
        startButton.setAction(placeCallAction);
        statusTable.getTable().setModel(manager.getStatusModel());
    }
}
